<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../style/js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="../style/js/ajaxfileupload.js" type="text/javascript"></script>
    <script type="text/javascript">
        /*让tomcat代管，UserImg 文件 */
    function fileUpload() {
        $.ajaxFileUpload({
                url: '../admin/fileUpload', //用于文件上传的服务器端请求地址  调用后端接口(interface)
                fileElementId: 'fileId', //文件上传域的ID
                dataType: 'json', //返回值类型 一般设置为json
                success: function (data){
                    if(data.code==200){
                        var account =  window.sessionStorage.getItem("account");//获取到当前登录人账号
                        var imgsrc =  "http://127.0.0.1:8080/UploadImg/"+account+"/"+data.data.newFileName;
                        window.parent.document.getElementById("imgId").innerHTML = "<img src='"+imgsrc+"' width='50' height='50'/>";
                    }
                }
            }
        )
    }
    </script>
</head>
<body>
上传头像
<input type="file" name="fileName" accept=".jpg,.png,.gif" id="fileId">
<input type="button" value="上传" onclick="fileUpload()">
</body>
</html>